FROM golang:1.17-alpine as builder
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories; \
    apk add --no-cache gcc musl-dev
ENV GOPROXY=https://goproxy.cn/
WORKDIR /usr/src/app
COPY go.mod go.sum ./
RUN go mod download && go mod verify

COPY . .
RUN go build \
    -ldflags "-s -w -linkmode external -extldflags '-static'"  \
    -tags musl  \
    -v  \
    -o /usr/local/bin/dproxy gitee.com/yysf-xin/dproxy/cmd/dproxy

FROM alpine:3.15
VOLUME /usr/local/dproxy
WORKDIR /usr/local/dproxy
EXPOSE 1080
COPY --from=builder /usr/local/bin/dproxy /usr/local/bin/dproxy
CMD ["dproxy"]